package com.webproject.core;

import java.util.Map;

import org.apache.log4j.Logger;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
import com.opensymphony.xwork2.interceptor.Interceptor;
import com.webproject.entity.sysManager.User;

/**
 * Timeout or no Login return Login.
 * @author lijiang
 *
 */
public class SessionInterceptor extends AbstractInterceptor {
	private Logger log=Logger.getLogger(getClass());
	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		Map<String, Object> session=arg0.getInvocationContext().getSession();
		String method=arg0.getInvocationContext().getName();
		if(!method.equals("login")){
			if(session.containsKey("user")){
				log.debug("session-------------------------------存在:"+((User)session.get("user")).getName());
				return arg0.invoke();
			}else{
				log.debug("session-------------------------------失效");
				return Action.INPUT;
			}
		}
		return arg0.invoke();
	}

}
